package edu.auctionmart

import org.joda.time.*
import static org.junit.Assert.*
import org.junit.*

class BidIntegrationTests {

	void testBid() {
		
		User seller = new User(username: "Russell", userRealName: "administrator", passwd: "Testinga4b", email: "russell@maine.edu")
		seller.save()
		
		User buyer = new User(username: "Brian", userRealName: "administrator", passwd: "Testinga4b", email: "brian@maine.edu")
		buyer.save()
		
		Item item = new Item(name: "Movie", description: "Some movie", category: ItemCategory.Electronics, quantity: 1)
		item.save()
		
		DateTime startTime = new DateTime(2012, 2, 12, 0, 0, 0)
		DateTime endTime = new DateTime(2012, 2, 15, 0, 0, 0)
				
		Auction auction = new Auction(auctionTitle: "Title", startBid: 0.01, seller: seller, item: item, startTime: startTime, endTime: endTime, status: AuctionStatus.OnGoing)
		auction.save()
		
		DateTime date = new DateTime()
		Bid bid = new Bid(auction: auction, userAccount: buyer, amount: 5.00, time: date)
		auction.addToBids(bid)
		bid.save()
		
		def foundBid = Bid.get(bid.id)
		assertNotNull(foundBid)
		
		assertEquals 1, Auction.get(auction.id).bids.size()
	}
}
